package com.markus.code.剑指offer;

/**
 * Author:markusZhang
 * Date:Create in 2020/8/31 13:25
 * todo: 股票的最大利润
 */
public class MaxProfit {
    public int maxProfit(int[] prices) {
        if (prices == null || prices.length == 0){
            return 0;
        }
        int max = 0;
        int profit = prices[0];
        for (int i=1;i<prices.length;i++){
            max = Math.max(prices[i]-profit,max);
            profit = Math.min(prices[i],profit);
        }
        return max;
    }

    public static void main(String[] args) {
        int []prices = {7,6,4,3,1};
        MaxProfit demo = new MaxProfit();
        System.out.println(demo.maxProfit(prices));
    }
}
